//
//  AYMPersonalHeadView.m
//  QuickCure
//
//  Created by 徐绩 on 16/5/7.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "AYMPersonalHeadView.h"

@implementation AYMPersonalHeadView

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
       
        [self setupUI];
    }
    return self;
}

#pragma mark - 布局界面,添加控件
-(void)setupUI{

    UserData *userData = [UserData sharedInstance];
    [userData loadUserInfoFromSanBox];
    
    UIImageView *iconImage = [[UIImageView alloc]init];
    [iconImage sd_setImageWithURL:[NSURL URLWithString:userData.head_photo] placeholderImage:[UIImage imageNamed:@"name"]];
    [self addSubview:iconImage];
    
    UIImageView *head = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"0"]];
    [self addSubview:head];
    
    UIImageView *idCardImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"idCard"]];
    [self addSubview:idCardImage];
    
    UIImageView *phoneImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"phone"]];
    [self addSubview:phoneImage];
    
    UILabel *nameLabel = [UILabel textColor:[UIColor blackColor] font:13];
    [self addSubview:nameLabel];
    
    UILabel *idCardLabel = [UILabel textColor:[UIColor blackColor] font:13];
    [self addSubview:idCardLabel];
    
    UILabel *phoeLabel = [UILabel textColor:[UIColor blackColor] font:13];
    [self addSubview:phoeLabel];
    
    nameLabel.text = userData.true_name;
    idCardLabel.text = userData.card_number;
    phoeLabel.text = userData.mobile_number;

    [iconImage makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.leading.equalTo(self).offset(30);
        make.width.height.equalTo(70);
    }];
    
    [head makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconImage);
        make.leading.equalTo(iconImage.trailing).offset(25);
        
    }];
    
    [idCardImage makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(head);
        make.centerY.equalTo(iconImage);
    }];
    
    [phoneImage makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(head);
        make.bottom.equalTo(iconImage);
    }];
    
    [nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(head);
        make.leading.equalTo(head.trailing).offset(20);
    }];
    
    [idCardLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(idCardImage);
        make.leading.equalTo(nameLabel);
    }];
    
    [phoeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(phoneImage);
        make.leading.equalTo(nameLabel);
    }];

}

@end
